package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Celebrity;
import com.ruoyi.system.service.ICelebrityService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参与人员Controller
 * 
 * @author ruoyi
 * @date 2024-01-18
 */
@Controller
@RequestMapping("/system/celebrity")
public class CelebrityController extends BaseController
{
    private String prefix = "system/celebrity";

    @Autowired
    private ICelebrityService celebrityService;

    @RequiresPermissions("system:celebrity:view")
    @GetMapping()
    public String celebrity()
    {
        return prefix + "/celebrity";
    }

    /**
     * 查询参与人员列表
     */
    @RequiresPermissions("system:celebrity:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Celebrity celebrity)
    {
        startPage();
        List<Celebrity> list = celebrityService.selectCelebrityList(celebrity);
        return getDataTable(list);
    }

    /**
     * 导出参与人员列表
     */
    @RequiresPermissions("system:celebrity:export")
    @Log(title = "参与人员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Celebrity celebrity)
    {
        List<Celebrity> list = celebrityService.selectCelebrityList(celebrity);
        ExcelUtil<Celebrity> util = new ExcelUtil<Celebrity>(Celebrity.class);
        return util.exportExcel(list, "参与人员数据");
    }

    /**
     * 新增参与人员
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存参与人员
     */
    @RequiresPermissions("system:celebrity:add")
    @Log(title = "参与人员", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Celebrity celebrity)
    {
        return toAjax(celebrityService.insertCelebrity(celebrity));
    }

    /**
     * 修改参与人员
     */
    @RequiresPermissions("system:celebrity:edit")
    @GetMapping("/edit/{celebrityId}")
    public String edit(@PathVariable("celebrityId") Long celebrityId, ModelMap mmap)
    {
        Celebrity celebrity = celebrityService.selectCelebrityByCelebrityId(celebrityId);
        mmap.put("celebrity", celebrity);
        return prefix + "/edit";
    }

    /**
     * 修改保存参与人员
     */
    @RequiresPermissions("system:celebrity:edit")
    @Log(title = "参与人员", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Celebrity celebrity)
    {
        return toAjax(celebrityService.updateCelebrity(celebrity));
    }

    /**
     * 删除参与人员
     */
    @RequiresPermissions("system:celebrity:remove")
    @Log(title = "参与人员", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(celebrityService.deleteCelebrityByCelebrityIds(ids));
    }
}
